package workers;

import domain.ConcurrentContainerInterface;

/**
 * @author igordv
 *
 */
public class PositiveProducer extends AbstractWorker {
	protected int m_amount;
	/**
	 * @param stack
	 */
	public PositiveProducer(ConcurrentContainerInterface<Integer> stack, int amount) {
		super(stack);
		m_amount = amount;
	}
	public PositiveProducer(ConcurrentContainerInterface<Integer> stack, int amount, int delay) {
		super(stack, delay);
		m_amount = amount;
	}
	/* (non-Javadoc)
	 * @see workers.AbstractWorker#description()
	 */
	@Override
	public String description() {
		return "PositiveProducer";
	}

	/* (non-Javadoc)
	 * @see workers.AbstractWorker#run()
	 */
	@Override
	public void threadLogic() {
		for (int i = 0; i < m_amount; i++) {
			m_container.insert(new Integer(i));
//			if (Math.random()>0.5) Thread.yield();
//			try {
//				Thread.sleep((long) (Math.random()*m_delayTimeInMillis));
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
		}
	}
}
